import java.util.Scanner;
import java.util.*;
public class Main {
    public static int compare(String s1,String s2) {
        if(s1.length() == s2.length()) return s1.compareTo(s2);
        return s1.length() - s2.length();
    }

    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String[] str = new String[n+1];
        for(int i = 1;i <= n;i++) {
            str[i] = in.next();
        }
        String max = "0";
        int num = 1;
        for(int i = 1;i <= n;i++) {
            if(compare(str[i],max) > 0) {
                max = str[i];
                num = i;
            }
        }
        System.out.println(num);
        for(int i = 0;i < str[num].length();i++)
            System.out.print(str[num].charAt(i));
        System.out.println();
    }

    ////////////////////////////////////
    //采药

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt(),m = in.nextInt();
        int[] time = new int[m+1];
        int[] value = new int[m+1];
        for(int i = 1;i <= m;i++) {
            time[i] = in.nextInt();
            value[i] = in.nextInt();
        }
        int[][] dp = new int[m+1][t+1];
        //采摘前i个草药，时间不超过j，得到的最大价值
        for(int i = 1;i <= m;i++) {
            for(int j = 0;j <= t;j++) {
                dp[i][j] = dp[i-1][j];
                if(j-time[i] >= 0) dp[i][j] = Math.max(dp[i-1][j],dp[i-1][j-time[i]] + value[i]);
            }
        }
        System.out.println(dp[m][t]);
    }

    //////////////////////////////////////////////
    public static void quickSort(int[] a,int l,int r) {
        if(l >= r) return;
        int i = l-1,j = r+1,key = a[(l+r) >> 1];
        while(i < j) {
            while(a[++i] < key);
            while(a[--j] > key);
            if(i < j) {
                int tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            }
        }
        quickSort(a,l,j);
        quickSort(a,j+1,r);
    }

    public static void main3(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[] a = new int[m];
        for(int i = 0;i < m;i++) {
            a[i] = in.nextInt();
        }
        quickSort(a,0,a.length-1);
        for(int i = 0;i < m;i++) {
            System.out.print(a[i]);
            if(i != m-1) System.out.print(" ");
        }
        System.out.println();
    }

    public static int coinChange(int[] coins, int amount) {
        //面额：体积  个数：价值  价值min
        int n = coins.length;
        int[][] dp = new int[n+10][amount+10];
        for(int i = 1;i <= amount;i++) {
            dp[0][i] = -1;
        }
        for(int i = 1;i <= n;i++) {
            for(int j = 0;j <= amount;j++) {
                dp[i][j] = dp[i-1][j];
                if(j - coins[i-1] >= 0 && dp[i][j-coins[i-1]] != -1) dp[i][j] = Math.min(dp[i-1][j],dp[i][j-coins[i-1]] + 1);
            }
        }
        return dp[n][amount];
    }

    public static void main(String[] args) {
        int[] a = {1,2,5};
        coinChange(a,11);
    }

}
